package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.RptInfo;
import com.ruoyi.mes.service.IRptInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报工Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "报工")
@RestController
@RequestMapping("/mes/rpt")
public class RptInfoController extends BaseController {
    @Autowired
    private IRptInfoService rptInfoService;

    /**
     * 查询报工列表
     */
    @ApiOperation(value = "查询报工列表")
    @PreAuthorize("@ss.hasPermi('mes:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(RptInfo rptInfo) {
        startPage();
        List<RptInfo> list = rptInfoService.selectRptInfoList(rptInfo);
        return getDataTable(list);
    }

    /**
     * 导出报工列表
     */
    @ApiOperation(value = "导出报工列表")
    @PreAuthorize("@ss.hasPermi('mes:info:export')")
    @Log(title = "报工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RptInfo rptInfo) {
        List<RptInfo> list = rptInfoService.selectRptInfoList(rptInfo);
        ExcelUtil<RptInfo> util = new ExcelUtil<RptInfo>(RptInfo.class);
        util.exportExcel(response, list, "报工数据");
    }

    /**
     * 获取报工详细信息
     */
    @ApiOperation(value = "获取报工详细信息")
    @PreAuthorize("@ss.hasPermi('mes:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rptInfoService.selectRptInfoById(id));
    }

    /**
     * 新增报工
     */
    @ApiOperation(value = "新增报工")
    @PreAuthorize("@ss.hasPermi('mes:info:add')")
    @Log(title = "报工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RptInfo rptInfo) {
        return toAjax(rptInfoService.insertRptInfo(rptInfo));
    }

    /**
     * 修改报工
     */
    @ApiOperation(value = "修改报工")
    @PreAuthorize("@ss.hasPermi('mes:info:edit')")
    @Log(title = "报工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RptInfo rptInfo) {
        return toAjax(rptInfoService.updateRptInfo(rptInfo));
    }

    /**
     * 删除报工
     */
    @ApiOperation(value = "删除报工")
    @PreAuthorize("@ss.hasPermi('mes:info:remove')")
    @Log(title = "报工", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rptInfoService.deleteRptInfoByIds(ids));
    }
}
